import request from '@/utils/request'
export * from './Article' // 从Article里接到所有导出,接着向外expport 导出
export * from './Channel'
// 登录
export const LoginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

// 获取用户的信息
export const getUserInfoAPI = () => request({
  url: '/v1_0/user'
})

// 获取用户的信息(生日)
export const userProfileAPI = () => request({
  url: '/v1_0/user/profile'
})

// 上传用户头像
export const uploadHeadImgAPI = (FormData) => request({
  url: '/v1_0/user/photo',
  method: 'PATCH',
  data: FormData
})

// 更改用户个人资料
export const uploadUserInfoAPI = ({ name = null, gender = null, birthday = null, real_name = null, intro = null }) => {
  const obj = {}
  if (name !== null) {
    obj.name = name
  }
  if (gender !== null) {
    obj.gender = gender
  }
  if (birthday !== null) {
    obj.birthday = birthday
  }
  if (real_name !== null) {
    obj.real_name = real_name
  }
  if (intro !== null) {
    obj.intro = intro
  }
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: obj
  })
}

// 刷新用户的token
export const refreshTokenAPI = () => request({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: {
    Authorization: 'Bearer ' + localStorage.getItem('refresh_token')
  }
})
